import time

from selenium import webdriver
from selenium.webdriver.common.by import By
driver = webdriver.Chrome()
driver.get('https://www.baidu.com')

# 定位--新闻--
time.sleep(2)
driver.find_element(By.LINK_TEXT,'新闻').click()
print(driver.title)

# 切换标签页
news_handle = driver.window_handles[1]
driver.switch_to.window(news_handle)

# 打印标题
print(driver.title)

index_handle = driver.window_handles[0]
driver.switch_to.window(index_handle)

#打印标题
print(driver.title)

# 退出浏览器
driver.quit()